<template>
  <div class="app-container">
    <!-- 查询条件 -->
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="状态" prop="sysNormalDisable">
        <el-select v-model="queryParams.sysNormalDisable" style="width: 250px" placeholder="请选择状态" clearable
                   size="small">
          <el-option
            v-for="dict in dict.type.sys_normal_disable"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="申请时间">
        <el-date-picker
          v-model="daterangeDocDt"
          size="small"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          style="width: 250px"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="审核结果" prop="oaDictConfirmStatus">
        <el-select v-model="queryParams.oaDictConfirmStatus" style="width: 250px" placeholder="请选择审核结果" clearable
                   size="small">
          <el-option
            v-for="dict in dict.type.oa_dict_confirm_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="申请人" prop="attentionUserNickName">
        <el-select
          filterable
          v-model="queryParams.attentionUserNickName"
          placeholder="请选择申请人"
          clearable
          size="small" style="width: 250px"
        >
          <el-option
            v-for="item in requestUserList"
            :key="item.userId"
            :label="item.nickName"
            :value="item.nickName"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="审核时间">
        <el-date-picker
          v-model="daterangeConfirmDt"
          size="small"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          style="width: 250px"
        ></el-date-picker>
      </el-form-item>

      <el-form-item label="单据编号" prop="docNum">
        <el-input
          v-model="queryParams.docNum"
          placeholder="请输入单据编号模糊查询"
          clearable
          size="small"
          @keyup.enter.native="handleQuery" style="width: 250px"
        />
      </el-form-item>
      <el-form-item label="审核人" prop="confirmUserNickName">
        <el-select
          filterable
          v-model="queryParams.confirmUserNickName"
          placeholder="请选择审核人"
          clearable
          size="small" style="width: 250px"
        >
          <el-option
            v-for="item in requestUserList"
            :key="item.userId"
            :label="item.nickName"
            :value="item.nickName"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 批量操作 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['pms:request:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['pms:request:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['pms:request:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['pms:request:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
    </el-row>

    <!-- 表格 -->
    <el-table v-loading="loading" stripe :data="requestList" :highlight-current-row="true"
              @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="50" align="center" fixed="left"/>
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-form label-position="left" class="demo-table-expand">
            <el-form-item label="备注：">
              <span>{{ props.row.docNote }}</span>
            </el-form-item>
            <el-form-item label="审核意见：">
              <span>{{ props.row.confirmNote }}</span>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column label="单据编号" align="center" prop="docNum" v-if="columns[1].visible" width="150"
                       :show-overflow-tooltip="true"/>
      <el-table-column label="申请日期" align="center" prop="docDt" width="150" v-if="columns[2].visible">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.docDt, '{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="申请人" align="center" prop="attentionUserNickName" v-if="columns[4].visible"/>
      <el-table-column label="审核人" align="center" prop="confirmUserNickName" v-if="columns[5].visible"/>
      <el-table-column label="审核时间" align="center" prop="confirmDt" width="120" v-if="columns[6].visible">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.confirmDt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核结果" align="center" prop="oaDictConfirmStatus" v-if="columns[7].visible">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.oa_dict_confirm_status" :value="scope.row.oaDictConfirmStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="sysNormalDisable" v-if="columns[3].visible">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.sysNormalDisable"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" fixed="right" width="180" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['pms:request:edit']"
          >修改
          </el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-circle-check"
            @click="handleConfirm(scope.row)"
            v-hasPermi="['oa:confirm:edit']"
            :disabled="scope.row.oaDictConfirmStatus !='waiting'">{{ $t('actions.confirm') }}
          </el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['crm:crmOrders:remove']"
            :disabled="scope.row.oaDictConfirmStatus !='editing'">删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <!--分页查询-->
    <pagination v-show="total>0"
                :total="total"
                :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize"
                @pagination="getList"/>

    <!-- 对话框：添加或修改采购申请 -->
    <el-dialog v-dialogDrag v-dialogDragWidth :title="title" :visible.sync="open" width="800px" append-to-body
               :close-on-click-modal=false>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-alert v-show="form.oaDictConfirmStatus != 'editing'"
                  style="margin-bottom: 15px;"
                  :title="form.latestTaskInfo"
                  type="info"
                  :closable="false"
                  effect="dark"
        >
        </el-alert>
        <el-row>
          <el-col :span="12">
            <el-form-item label="单据编号" prop="docNum">
              <el-input v-model="form.docNum" placeholder="请输入单据编号"
                        />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item prop="docDt">
                    <span slot="label">
                      单据时间
                     <el-tooltip content="单据时间为采购申请时间" placement="top">
                      <i class="el-icon-question"></i>
                      </el-tooltip>
                    </span>
              <el-date-picker clearable size="small"
                              v-model="form.docDt"
                              type="datetime"
                              placeholder="选择单据时间"
                              :style="{width: '100%'}"
                              value-format="yyyy-MM-dd HH:mm"
                              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="申请人" prop="fkAttentionUserId">
              <el-input v-model:value="form.fkAttentionUserId" v-show="false"/>
              <el-input placeholder="请选择申请人" v-model="form.attentionUserName" class="input-with-select"
                        >
                <el-button @click="dialog_show_selectUser" slot="append" icon="el-icon-search"
                           ></el-button>
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="状态">
              <el-radio-group v-model="form.sysNormalDisable">
                <el-radio
                  v-for="dict in dict.type.sys_normal_disable"
                  :key="dict.value"
                  :label="dict.value"
                >{{dict.label}}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="备注" prop="docNote">
              <el-input v-model="form.docNote" type="textarea" autosize placeholder="请输入内容"
                         maxlength="50"
                        show-word-limit/>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 批量按钮 -->
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" icon="el-icon-plus" size="mini"
                       @click="handleAddPmsRequestDetails">添加
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-delete" size="mini"
                       @click="handleDeletePmsRequestDetails">删除
            </el-button>
          </el-col>
        </el-row>

        <el-table :data="pmsRequestDetailsList" :row-class-name="rowPmsRequestDetailsIndex"
                  @selection-change="handlePmsRequestDetailsSelectionChange" ref="pmsRequestDetails">
          <el-table-column type="selection" width="50" align="center"
                           />
          <el-table-column label="序号" align="center" prop="index" width="50" v-if="false"/>
          <el-table-column label="序号" prop="orderNum">
            <template slot-scope="scope">
              <el-input v-model="scope.row.orderNum" placeholder="请输入排序序号"
                        />
            </template>
          </el-table-column>


          <el-table-column label="物料名称" prop="itemName" width="180px" align="center">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fkItemUuid" v-show="false"/>
              <el-input placeholder="请选择物料名称"
                        v-model="scope.row.selectedItem"
                        class="input-with-select"
                        >
                <el-button @click="dialog_show_selectItem(scope)" slot="append" icon="el-icon-search"
                           ></el-button>
              </el-input>
            </template>
          </el-table-column>

          <el-table-column label="物料编码" prop="itemNum" width="240px"  align="center">
            <template slot-scope="scope">
              <el-input v-model="scope.row.itemNum" placeholder="选择物料自动带出"  :disabled="disabled" width="240"
              />
            </template>
          </el-table-column>

          <el-table-column label="数量" prop="requestQty" width="150px" align="center">
            <template slot-scope="scope">
              <el-input v-model="scope.row.requestQty" placeholder="请输入数量" style="width: 120px"
                        />
            </template>
          </el-table-column>

          <el-table-column label="计量单位" prop="wmsDictMeasuringUnit" align="center" width="150px">
            <template slot-scope="scope">
              <el-select filterable
                         v-model="scope.row.wmsDictMeasuringUnit"
                         placeholder="请选择"
                         style="width: 120px"
              >
                <el-option
                  v-for="dict in measuringUnitOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </template>
          </el-table-column>

          <el-table-column label="紧急程度" prop="crmDictUrgencyLevel" width="200px" align="center">
            <template slot-scope="scope">
              <el-select
                v-model="scope.row.crmDictUrgencyLevel"
                placeholder="请选择"
                style="width: 150px"
              >
                <el-option
                  v-for="dict in urgencyOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </template>
          </el-table-column>

          <el-table-column label="备注" prop="note" width="200" align="center">
            <template slot-scope="scope">
              <el-input v-model="scope.row.note"
                        placeholder="请输入备注"
                        maxlength="50"
                        show-word-limit
                        type="textarea"
                        autosize/>
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" :disabled="form.oaDictConfirmStatus != 'editing'">确 定</el-button>
        <el-button type="warning" @click="submitForm('waiting')" :disabled="form.oaDictConfirmStatus != 'editing'">提交待审
        </el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 核实采购申请对话框 -->
    <el-dialog v-dialogDrag v-dialogDragWidth :title="title" :visible.sync="open_confirm" width="800px" append-to-body>
      <el-form ref="form" :model="form" label-width="100px">
        <div>
          <el-tabs type="border-card">
            <el-tab-pane label="采购申请基本信息">
              <el-row>
                <el-col :span="12">
                  <el-form-item label="单据编号:" prop="docNum">
                    {{form.docNum}}
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="申请时间:" prop="dcoDt">
                    {{parseTime(form.docDt, '{y}-{m}-{d} {h}:{i}')}}
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="申请人:" prop="attentionUserNickName">
                    {{form.attentionUserNickName}}
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="备注:" prop="docNote">
                    {{form.docNote}}
                  </el-form-item>
                </el-col>
              </el-row>
            </el-tab-pane>
            <el-tab-pane label="采购申请明细信息">
              <el-table :data="pmsRequestDetailsList" :row-class-name="rowPmsRequestDetailsIndex"
                        @selection-change="handlePmsRequestDetailsSelectionChange" ref="pmsRequestDetails">
                <el-table-column label="序号" align="center" prop="index" width="50"/>
                <el-table-column label="物料名称" align="center" prop="itemName"/>
                <el-table-column label="数量" align="center" prop="requestQty"/>
                <el-table-column label="紧急程度" align="center" prop="crmDictUrgencyLevel">
                  <template slot-scope="scope">
                    <dict-tag :options="dict.type.crm_dict_urgency_level" :value="scope.row.crmDictUrgencyLevel"/>
                  </template>
                </el-table-column>
                <el-table-column label="备注" align="center" prop="note"/>
              </el-table>
            </el-tab-pane>
          </el-tabs>
        </div>
        <div style="width:5px;height:20px;color: #6793c6"/>
        <el-divider content-position="left">审核意见</el-divider>
        <el-col :span="12">
          <el-form-item label="审批结果" prop="oaDictConfirmStatus">
            <el-select v-model="form.oaDictConfirmStatus" placeholder="请选择审批结果">
              <el-option
                v-for="dict in resultOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="意见建议" prop="confirmNote">
            <el-input v-model="form.confirmNote"
                      placeholder="请输入意见建议"
                      type="textarea"
                      autosize
                      maxlength="50"
                      show-word-limit/>
          </el-form-item>
        </el-col>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirmForm">确 定</el-button>
        <el-button @click="cancel_confirm">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 组件 -->
    <select-user ref="component_selectUser" :roleId="queryParams.roleId" @ok="selectUser_done"/>
    <select-item ref="component_selectItem" @ok="selectItem_done"/>
    <confirm ref="component_confirm" @ok="confirm_done"/>

  </div>
</template>

<script>
  import {listRequest, getRequest, delRequest, addRequest, updateRequest, confirmRequest} from "@/api/pms/request";
  import {newDocNum} from "@/api/oa/docNum";
  import {parseTime} from '@/utils/ruoyi'
  import selectUser from "../../comn/userGroup/selectUser";
  import selectItem from "../../wms/wmsItems/selectItem";
  import confirm from "../../oa/confirm";
  import {listUser} from "@/api/system/user";

  export default {
    name: "Request",
    dicts: ['sys_normal_disable', 'oa_dict_confirm_status', 'crm_dict_urgency_level', 'wms_dict_measuring_unit',],
    components: {selectItem, selectUser, confirm},
    data() {
      return {

        urgencyOptions: [],
        resultOptions: [],
        measuringUnitOptions: [],
        requestDetails_currRowScope: null, // 订单明细：当前行

        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 子表选中数据
        checkedPmsRequestDetails: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        disabled: true,
        // 总条数
        total: 0,
        // 采购申请表格数据
        requestList: [],
        //用户列表
        requestUserList: [],
        // 采购申请表格数据
        pmsRequestDetailsList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 是否显示弹出层
        open_confirm: false,
        // 备注时间范围
        daterangeDocDt: [],
        // 备注时间范围
        daterangeConfirmDt: [],
        // 备注时间范围
        daterangeCreateTime: [],
        // 备注时间范围
        daterangeUpdateTime: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          sysNormalDisable: null,
          docTitle: null,
          docNum: null,
          docDt: null,
          docNote: null,
          fkAttentionUserId: null,
          fkConfirmUserId: null,
          confirmDt: null,
          oaDictConfirmStatus: null,
          confirmNote: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          sysNormalDisable: [
            {required: true, message: "状态不能为空", trigger: "change"}
          ],
          docNum: [
            {required: true, message: "单据编号不能为空", trigger: "change"}
          ],
          docDt: [
            {required: true, message: "请输入单据时间", trigger: "change"}
          ],
          fkAttentionUserId: [
            {required: true, message: "请选择申请人", trigger: "change"}
          ],
          createTime: [
            {required: true, message: "创建时间不能为空", trigger: "blur"}
          ],
        },
        columns: [
          {key: 1, label: `单据编号`, visible: true},
          {key: 2, label: `申请日期`, visible: true},
          {key: 3, label: `状态`, visible: true},
          {key: 4, label: `申请人`, visible: true},
          {key: 5, label: `审核人`, visible: true},
          {key: 6, label: `审核时间`, visible: true},
          {key: 7, label: `审核结果`, visible: true},
          {key: 8, label: `审核意见`, visible: true},
        ],

      };
    },
    created() {

      this.getList();

      this.getList_requestUser();

      /**获取紧急程度字典数据*/
      this.getDicts("crm_dict_urgency_level").then(response => {
        this.urgencyOptions = response.data;
      });

      /**获取计量单位字典数据*/
      this.getDicts("wms_dict_measuring_unit").then(response => {
        this.measuringUnitOptions = response.data;
      });

      /**获取确认结果字典数据*/
      this.getDicts("oa_dict_confirm_status").then(response => {
        this.resultOptions = response.data;
      });

    },
    methods: {

      /** 查询采购申请列表 */
      getList() {
        this.loading = true;
        this.queryParams.params = {};
        if (null != this.daterangeDocDt && '' != this.daterangeDocDt) {
          this.queryParams.params["beginDocDt"] = this.daterangeDocDt[0];
          this.queryParams.params["endDocDt"] = this.daterangeDocDt[1];
        }
        if (null != this.daterangeConfirmDt && '' != this.daterangeConfirmDt) {
          this.queryParams.params["beginConfirmDt"] = this.daterangeConfirmDt[0];
          this.queryParams.params["endConfirmDt"] = this.daterangeConfirmDt[1];
        }
        if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
          this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
          this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
        }
        if (null != this.daterangeUpdateTime && '' != this.daterangeUpdateTime) {
          this.queryParams.params["beginUpdateTime"] = this.daterangeUpdateTime[0];
          this.queryParams.params["endUpdateTime"] = this.daterangeUpdateTime[1];
        }
        listRequest(this.queryParams).then(response => {
          this.requestList = response.rows;
          this.total = response.total;
          this.loading = false;
        });

      },
      getList_requestUser() {
        listUser().then(response => {
          this.requestUserList = response.rows
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 取消按钮
      cancel_confirm() {
        this.open_confirm = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          requestUuid: null,
          sysNormalDisable: '0',
          docTitle: null,
          docNum: null,
          docDt: parseTime(Date.now(), '{y}-{m}-{d} {h}:{i}'),
          docNote: null,
          fkAttentionUserId: null,
          fkConfirmUserId: null,
          confirmUserNickName: null,
          attentionUserNickName: null,
          confirmDt: null,
          oaDictConfirmStatus: 'editing',
          confirmNote: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null
        };
        this.pmsRequestDetailsList = [];
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.daterangeDocDt = [];
        this.daterangeConfirmDt = [];
        this.daterangeCreateTime = [];
        this.daterangeUpdateTime = [];
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.requestUuid)
        this.docNums = selection.map(item => item.docNum)
        this.single = selection.length !== 1
        this.oaDictConfirmStatus = selection.map(i => i.oaDictConfirmStatus)
        let editing = 'editing';
        this.multiple =
          (this.oaDictConfirmStatus.indexOf(editing) > -1 && [...new Set(this.oaDictConfirmStatus)] == editing) ? false : true
      },
      /** 新增按钮操作 */
      handleAdd() {

        newDocNum({preCode: 'REQ-', len: 12}).then(response => {
          this.form.docNum = response.msg
          console.log(this.form.docNum)
        })

        this.reset();
        this.form.oaDictConfirmStatus = 'editing'
        this.open = true;
        this.title = "添加采购申请";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.open = true;
        this.title = "修改采购申请";
        this.reset();
        const requestUuid = row.requestUuid || this.ids
        getRequest(requestUuid).then(response => {
          let d = response.data

          // 经办人
          d.attentionUserName = d.attentionUserNickName
          this.form = d

          if (d.pmsRequestDetailsList) {
            d.pmsRequestDetailsList.forEach(function (item, index) {
              // 物料名称
              item.selectedItem = item.itemName
              item.itemNum = item.itemNum
            })
          }
          // 审核
          this.form.oaDictConfirmStatus =
            ('editing' == this.form.oaDictConfirmStatus || 'reject' == this.form.oaDictConfirmStatus)
              ? 'editing' : this.form.oaDictConfirmStatus

          if (row.oaDictConfirmStatus != 'editing' || row.oaDictConfirmStatus != 'reject') {
            this.form.latestTaskInfo = '💡 该条记录审核状态为' +
              this.selectDictLabel(this.dict.type.oa_dict_confirm_status, row.oaDictConfirmStatus) + '状态' + ',' + '不能修改'
          }

          this.pmsRequestDetailsList = d.pmsRequestDetailsList;


        });
      },
      /** 审核按钮操作 */
      handleConfirm(row) {
        this.reset();
        const requestUuid = row.requestUuid || this.ids
        getRequest(requestUuid).then(response => {
          this.form = response.data;
          this.form.oaDictConfirmStatus = 'pass'
          this.pmsRequestDetailsList = response.data.pmsRequestDetailsList;
          this.open_confirm = true;
          this.title = "核实采购申请";
        });
      },
      /** 提交按钮 */
      submitForm(confirmStatus) {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if(confirmStatus=='waiting') this.form.oaDictConfirmStatus = confirmStatus
            this.form.pmsRequestDetailsList = this.pmsRequestDetailsList;
            if (this.form.requestUuid != null) {
              updateRequest(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addRequest(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      submit_confirm() {
        this.form.oaDictConfirmStatus = 'waiting'
        updateRequest(this.form).then(response => {
          this.$modal.msgSuccess("提交待审成功");
          this.open = false;
          this.getList();
        });
      },
      /**审核提交按钮*/
      confirmForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            this.form.pmsRequestDetailsList = this.pmsRequestDetailsList;
            this.form.fkConfirmUserId = this.$store.state.user.userId;
            console.log(this.form.fkConfirmUserId)
            confirmRequest(this.form).then(response => {
              this.$modal.msgSuccess("核实成功");
              this.open_confirm = false;
              this.getList();
            });
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const requestUuids = row.requestUuid || this.ids;
        const docNums = row.docNum || this.docNums;
        this.$modal.confirm('是否确认删除单据编号为"' + docNums + '"的采购申请单？').then(function () {
          return delRequest(requestUuids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {
        });
      },
      /** 采购申请序号 */
      rowPmsRequestDetailsIndex({row, rowIndex}) {
        row.index = rowIndex + 1;
      },
      /** 采购申请添加按钮操作 */
      handleAddPmsRequestDetails() {
        let obj = {};
        obj.orderNum = "1";
        obj.fkItemUuid = "";
        obj.selectedItem = "";
        obj.itemNum = "";
        obj.wmsDictMeasuringUnit = "";
        obj.requestQty = "";
        obj.crmDictUrgencyLevel = "1";
        obj.note = "";
        this.pmsRequestDetailsList.push(obj);
      },
      /** 采购申请删除按钮操作 */
      handleDeletePmsRequestDetails() {
        if (this.checkedPmsRequestDetails.length == 0) {
          this.$modal.msgError("请先选择要删除的采购申请数据");
        } else {
          const pmsRequestDetailsList = this.pmsRequestDetailsList;
          const checkedPmsRequestDetails = this.checkedPmsRequestDetails;
          this.pmsRequestDetailsList = pmsRequestDetailsList.filter(function (item) {
            return checkedPmsRequestDetails.indexOf(item.index) == -1
          });
        }
      },
      /** 复选框选中数据 */
      handlePmsRequestDetailsSelectionChange(selection) {
        this.checkedPmsRequestDetails = selection.map(item => item.index)
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('pms/request/export', {
          ...this.queryParams
        }, `pms_request.xlsx`)
      },


      /** 打开授权用户表弹窗 */
      dialog_show_selectUser() {
        this.$refs.component_selectUser.show();
      },


      /** 选择用户完成 */
      selectUser_done(user) {
        this.form.fkAttentionUserId = user.userId
        this.form.attentionUserName = user.nickName
        // this.$refs["form"].validate() // 重新校验表单
      },


      /** 显示对话框：选择物料 */
      dialog_show_selectItem(scope) {
        console.log(scope)
        this.requestDetails_currRowScope = scope
        this.$refs.component_selectItem.dialog_show_selectItem();
      },

      // 完成：选择物料
      selectItem_done(item) {
        this.requestDetails_currRowScope.row.fkItemUuid = item.itemUuid
        this.requestDetails_currRowScope.row.selectedItem = item.itemName
        this.requestDetails_currRowScope.row.itemNum = item.itemNum
        this.requestDetails_currRowScope.row.wmsDictMeasuringUnit = item.wmsDictMeasuringUnit
      },


      confirm_done() {
      },


    }
  };
</script>
